
		<div style="padding:10px">
        </div>
		<div class="blockcms">
            <div style="font-size:18px;font-weight:bold;">
                <?=$this->translate->_('Shopping Cart')?>
            </div>
            <div class="story" style="padding:0px">
            
                <form name="yourCartForm" id="yourCartForm" action="<?=$this->linkPost?>" method="post">
                <?php
                $yourCart = $this->yourCart;
                 
                if (count($yourCart) > 0 ) {
                ?>
    <div class="">
        <div class="blockcontent">
            <div style="padding:0px">
                <?php
                    $defaultNamespace = new Zend_Session_Namespace('Default');
                    $sum = 0;
                    $stt = 1;
                    $bgcolor = array('#FFFFFF', '#EFEFEF');
                    $strItem = "";
                    $i = 0;
                    ?>
                        <div class="div-clear"></div>
                    <table width="100%" border="0" cellspacing="0" cellpadding="5" class="carttable">
                        <thead>
                        <tr>
                            <td colspan="7">
                                <div style="background:#C0C0C0;padding:5px 10px;margin:10px 0px;text-align:left;">
                                    <?=$this->translate->_('Items')?>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th width="20"></th>
                            <th width="20"><?=$this->translate->_('Qty')?></th>
                            <th width="20"><?=$this->translate->_('SKU')?></th>
                            <th style="text-align:left"><?=$this->translate->_('Description')?></th>
                            <th width="70"><?=$this->translate->_('Price')?></th>
                            <th width="50"><?=$this->translate->_('Coupon')?></th>
                            <th width="50" style="text-align:right;"><?=$this->translate->_('Total')?></th>
                        </tr>
                        </thead>
                        <tbody>
                    <?php
                    $saving = 0;
                    $allCategory = $this->allCategory;
                    foreach ($yourCart as $item):
                    //echo 'ABCDEF' .  $amount['' . $item->ProductNo]['amount'];
                    
                        //$attr = $amount['' . $item->ProductNo]['Attribute'];
                        //foreach($attr as $attKey => $att):
                            $price = $item->Price; 
                            //$priceretail = $item->PriceRetail;
                            $attKey = $item->Attribute;
                            $strItem .= ($i++ >0 ? ",":"") . $item->ProductNo . '-' . htmlspecialchars($attKey);
                            
                            //$path = pathinfo($item->Thumbnail, PATHINFO_DIRNAME);
                            //$fileName = pathinfo($item->Thumbnail, PATHINFO_BASENAME);
                            
                    ?>
                            <tr <?php if ($i%2==0) {?>class="odd"<?php } ?>>
                                <td style="text-align:right">
                                    <a href="javascript:deleteItemFromYourCart(<?=$item->ProductNo?>, '<?=htmlspecialchars($attKey)?>');"><?=$this->translate->_('Remove')?></a>
                                </td>
                                <td>
                                    <?=$this->formText('amount' . $item->ProductNo . '-' . htmlspecialchars($attKey), $item->Quantity, array('style' => 'width:40px;', 'maxlength' => '5', 'onchange' => "javascript:checkNumber(this);", 'onkeyup' => "javascript:checkNumber(this);"))?>
                                </td>
                                <td style="text-align:left">
                                        <?php
                                        //echo $item->SKU;
                                        ?>
                                </td>
                                <td style="text-align:left">
                                        <?=$item->Product?>
                                        <?php
                                        echo "<br>ProductNo: " . $item->ProductNo;
                                        if($attKey) {
                                            echo " - Attribute: " . $attKey;
                                        }
                                        ?>
                                    <!--a class="shop_center" href="<?=BASE_URL?>/index/index/detail/id/<?=$item->ProductNo?>"></a-->
                                </td>
                                <td>
                                    <?= $price?>
                                    <?php
                                        $subTotal = $price * $item->Quantity;
                                    ?>
                                </td>
                                <td style="text-align:right;">
                                    <?php 
                            $coupon = $defaultNamespace->coupon;
                            
                            $hasCoupon = false;
                            if ($coupon) {
                                $hasCoupon = true;
                            }
                            if ($hasCoupon && $item->DiscountYN != 'No') {
                                    
                                $realCoupon = 0;
                                if (@$coupon['CouponType'] && @$coupon['Value']) {
                                    $couponType = $coupon['CouponType'];
                                    $couponCode = $coupon['CouponCode'];
                                    $couponValue = $coupon['Value'];
                                    $couponCatID = $coupon['CatID'];
                                    
                                    
                                    $children = array();
                                    @$children = $allCategory[$couponCatID]['children'];
                                    $children[] = $couponCatID;
                                    
                                    if ($couponCatID == null || in_array($item->CatID, $children)) {
                                        if ($couponType == '%') {
                                            $realCoupon = round($subTotal * ($couponValue)/100, 2);
                                            $saving += $realCoupon;
                                        } elseif($couponType == '$') {
                                            //$realCoupon = $couponValue;
                                        }
                                        $subTotal -= $realCoupon;
                                    }
                                }
                                echo "-" . $realCoupon;
                            }
                                        $sum += $subTotal;
                                    ?>
                                </td>
                                <td style="text-align:right;">
                                    <?php echo $subTotal?>
                                </td>
                            </tr>
                <?php
                        //endforeach; // Attribute
                    endforeach; // item
                   echo $this->formHidden('items', $strItem, array('size' => 10));   
                ?>
                        <input type="hidden" id="totalnotcoupon" value="<?=$sum?>">
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="7" style="text-align:right;">
                                <div style="padding:5px">
                                    <hr noshade="" size="1" color="#c0c0c0"/>
                                </div>
                                <div style="padding: 10px;text-align:left">
                                    <div style="float:left">
                                    <input type="submit" class="updatecart" value="">
                                    </div>
                                    <div style="float:left;padding:0px 20px 0px 20px;">
                                    <?php
                                    $defaultNamespace = new Zend_Session_Namespace('Default');
                                    
                                    $defaultNamespace->cartTotal = $sum;
                                    
                                    $coupon = $defaultNamespace->coupon;
                                    $couponCode = "";
                                    @$couponTitle = $coupon['CouponTitle'];
                                    
                                    $sumWithCoupon = $sum;
                                    
                                    if (@$coupon['CouponType'] && @$coupon['Value']) {
                                        $couponType = $coupon['CouponType'];
                                        $couponCode = $coupon['CouponCode'];
                                        $couponTitle = $coupon['CouponTitle'];
                                        $couponValue = $coupon['Value'];
                                        
                                        if ($couponType == '%') {
                                            //$saving = $sum*$couponValue/100;
                                            //$sumWithCoupon = $sum * (100 - $couponValue)/100;
                                        } elseif($couponType == '$') {
                                            $sumWithCoupon -= $couponValue;
                                            $saving = $couponValue;
                                        }
                                        $defaultNamespace->realCoupon = $saving;
                                    }
                                    ?>
                                    <input type="hidden" id="totalwithcoupon" value="<?=$sumWithCoupon?>">
                                        Promotion Code: 
                                            <input type="text" name="PromotionCode" id="PromotionCode" style="padding:2px;width:50px" value="<?php echo $couponCode?>">
                                            <?php
                                            echo "<span class='pink'>" . $couponTitle . "</span>";
                                            ?>
                                            <br>
                                            <input type="button" value="Update Promotion Code" id="PromotionCodeButton">
                                <div>
                                            <div id="PromotionCodeMessage" style="color:red;line-height:20px">
                                            <?php
                                            if (@$couponValue) {
                                            ?>
                                            <a href="<?php echo BASE_URL?>/index/shop/removecoupon" style="color:#005974">REMOVE -></a> Coupon: $<?php echo $saving;?>
                                            <?php
                                            }
                                            ?>
                                            </div>
                                            
                                </div>
                                    </div>
                                    <div style="clear:both"></div>
                                </div>
                                <b><?=$this->translate->_('Sub-Total')?>:</b> 
                                <span style="padding:0px 0px 0px 10px">$<?=$sumWithCoupon?></span>
                                <b style="line-height:20px">
                                    <br>
                                    Recommended* Add Signature Confirmation (+$2.00)
                                    <span style="padding:0px">
                                    <input type="checkbox" id="SignatureConfirmation" value="1" <?php if($defaultNamespace->SignatureConfirmation == 1) echo "checked";?>>
                                    <?php 
                                    if($defaultNamespace->SignatureConfirmation == 1) {
                                        echo "$2";
                                        $sumWithCoupon += 2;
                                    }
                                    ?>
                                    </span>
                                </b>
                                <div id="StoreCredit" style="color:red;line-height:20px">
                                <?php
                                $StoreCredit = 0;
                                // get Store Credit from DB
                                $user = $defaultNamespace->user;
                                @$StoreCredit = $user->StoreCredit;
                                
                                $StoreCredit = $StoreCredit>=$sumWithCoupon?$sumWithCoupon:$StoreCredit;
                                
                                if($StoreCredit > 0) {
                                    $defaultNamespace->StoreCredit = $StoreCredit;
                                    
                                    $sumWithCoupon -= $StoreCredit;
                                    echo "Store credit: $" . $StoreCredit;
                                }
                                ?>
                                </div>
                                <div id="updategiftcard" style="color:red;line-height:20px">
                                <?php
                                $giftCard = $defaultNamespace->giftCard;
                                $giftCardPrice = $defaultNamespace->giftCardPrice;
                                
                                $giftCardPrice = $giftCardPrice>=$sumWithCoupon?$sumWithCoupon:$giftCardPrice;
                                if($giftCardPrice > 0) {
                                    $sumWithCoupon -= $giftCardPrice;
                                    ?>
                                    <a href="<?php echo BASE_URL?>/index/shop/removegiftcart" style="color:#005974">REMOVE -></a> Gift card: $<?php echo $giftCardPrice;?>
                                <?php
                                } else {
                                    $defaultNamespace->giftCard = null;
                                    $defaultNamespace->giftCardPrice = null;
                                }
                                ?>
                                </div>
                                    <div>
                                            <div>
                                            ESTIMATED TOTAL 	
                                            <span style="padding:0px 0px 0px 10px">
                                                <b style="line-height:20px">
                                                    $<span id="estimatetotal"><?=$sumWithCoupon?></span>
                                                </b>
                                            </div>
                                        <script>
                                            function goToViewCart() {
                                                location.href = '<?php echo BASE_URL?>/index/shop/viewcart';
                                            }
                                            $('#PromotionCodeButton').click(function() {
                                                if($('#PromotionCode').val() != '') {
                                                    $.ajax({
                                                        url: "<?=BASE_URL?>/index/shop/promotioncode",
                                                        type: "POST",
                                                        data:{PromotionCode: $('#PromotionCode').val()},
                                                        dataType: "json",
                                                        beforeSend: function(){
                                                            $.prompt('Please wait ...',{ buttons: {} });
                                                        },
                                                        success: function(responseText){
                                                            jQuery.prompt.close();
                                                            $.prompt(responseText.msg,{ 
                                                                    buttons: { Ok: true }, zIndex : 1000000000 
                                                                    ,callback:goToViewCart
                                                                }
                                                            );
                                                            //$("#PromotionCodeMessage").html(responseText.msg);
                                                            var value = responseText.Value;
                                                            var oldTotal = $('#totalnotcoupon').val();
                                                            if (responseText.success == true) {
                                                            
                                                                /*
                                                                if (responseText.CouponType == "$") {
                                                                    $('#estimatetotal').text(oldTotal - value);
                                                                    var html = $("#PromotionCodeMessage").html();
                                                                    //$("#PromotionCodeMessage").html(html + '<br>Coupon: $' + value);
                                                                    $("#PromotionCodeMessage").html('Coupon: $' + value);
                                                                } else {
                                                                    if (responseText.CouponType == "%") {
                                                                        //console.log($('#estimatetotal').text(oldTotal - oldTotal*value/100));
                                                                        var html = $("#PromotionCodeMessage").html();
                                                                        //$("#PromotionCodeMessage").html(html + '<br>Saving: $' + oldTotal*value/100);
                                                                        $("#PromotionCodeMessage").html('Coupon: $' + oldTotal*value/100);
                                                                    }
                                                                }
                                                                */
                                                                
                                                                //location.href = '<?php echo BASE_URL?>/index/shop/viewcart';
                                                            } else {
                                                                $('#estimatetotal').text(oldTotal);
                                                                //location.href = '<?php echo BASE_URL?>/index/shop/viewcart';
                                                            }
                                                        },
                                                        error: function(html){
                                                            jQuery.prompt.close();
                                                            $.prompt('Please check Promotion Code...',{ buttons: {} });
                                                        }
                                                    }); 
                                                }
                                            });
                                        </script>
                                    </div>
                                    
                                
                            <td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
                            
                    <!--input type="hidden" value="<?=$strItem?>" name="items"-->
                    <div>
                        <div style="padding:10px;font-size:18px;float:left;">
                            <?=$this->translate->_('Checkout Options')?>
                        </div>
                        <?php
                        if(!$defaultNamespace->access) {
                        ?>
                        <div style="padding:10px;font-size:18px;float:right;" class="pink">
                            <a href="<?php echo BASE_URL;?>/index/shop/usestore">If you have Store Credit, login here to redeem</a>
                        </div>
                        <?php
                        }
                        ?>
                        <div style="clear:both;"></div>
                    </div>
                    
                </div>
            </div>

                <?php
                } // if count > 0
                else {
                    echo $this->translate->_('Your Cart empty');
                }
                 ?>
                </form>


                    <div style="padding:10px">
                        <table width="100%">
                            <tr>
                                <td>
                                    <span class="muiten">
                                        <a style="text-align: left;" class="shop_center" href="<?=BASE_URL?>">
                                            <img border="0" alt="" src="<?php echo JS_PATH?>/skincarebyalana/images/continue.gif"/>
                                        </a>
                                    </span>
                                </td>
                                <?php
                                if (count($yourCart) > 0 ) {
                                ?>
                                <td align="right">
                                    <span class="muiten">
                                        <a class="shop_center" href="#giftcard" id="giftcardpopup">
                                            <img border="0" name="checkout" src="<?php echo JS_PATH?>/skincarebyalana/images/giftcardcheckout.jpg">
                                        </a>
                                        <a class="shop_center" href="<?=BASE_URL?>/shop/checkuser?m=pp">
                                            <img border="0" name="checkout" src="<?php echo JS_PATH?>/skincarebyalana/images/paypal-donate-button.png">
                                        </a>
                                        <a class="shop_center" href="<?=BASE_URL?>/shop/checkuser?m=cc">
                                            <img border="0" name="checkout" src="<?php echo JS_PATH?>/skincarebyalana/images/proceedtocheckout.gif">
                                        </a>
                                        <div style="display:none;">
                                            <div id="giftcard" style="width:300px;height:120px">
        <div style="font-size:16px">
            Gift card checkout
        </div>
        <hr noshade="" size="1" color="#c0c0c0"/>
        
        <form action="<?=BASE_URL?>/index/shop/updatgiftcard" method="post" id="giftcardprocesspayment">
            <table>
                <tr>
                    <td width="150">
                        Your Gift Card number
                    </td>
                    <td>
                        <input type="text" name="gcno" id="gcno" value="" class="required uniform">
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input type="submit" class="uniform" value="Submit">
                        <input type="reset" class="uniform" value="Reset">
                    </td>
                </tr>
            </table>
        </form>

                                            </div>
                                        </div>
                                    </span>
                                </td>
                                <?php
                                } // if count cart
                                ?>
                            </tr>
                        </table>
                        <div style="clear:both;"></div>
                        <?php
                        if (count($yourCart) > 0 ) {
                        ?>
                        <div style="text-align:center">
                            <span class="muiten"><a style="text-align: left;" class="shop_center" href="<?=BASE_URL?>/shop/emptycart"><?=$this->translate->_('Empty cart')?></a></span>
                            <div style="padding:10px">
                                <i>Note: Residents of some states may be subject to sales tax.</i>
                            </div>
                        </div>
                        <?php
                        } // if count cart
                        ?>
                    </div>

                <div style="clear: both;"></div>
            </div>

            
		</div>



<script type="text/javascript">
	function checkNumber(object)
	{
		object.value = object.value.replace(/[^0-9]/g, '');
		if (object.value == '')
		{
			object.value = 0;
		}
	}
    function deleteItemFromYourCart(id, att){
        var strID = "amount" +id + '-' + att;
        var obj = $('#' + strID);
        obj.val(0);
        $('#yourCartForm').submit();
    }
    
</script>
<style>
.carttable th{text-align:center}
.carttable{text-align:center}
hr {
border-color:#000000 -moz-use-text-color -moz-use-text-color;
border-style:dashed none none;
border-width:1px 0 0;
margin:10px 0;
}
.carttable tbody tr:hover{
    background:#abcdef;
}
</style>

<script type="text/javascript" src="<?php echo JS_PATH ?>/jquery/jquery.fancybox-1.3.2/fancybox/jquery.fancybox-1.3.2.pack.js"></script>
<link rel="stylesheet" href="<?php echo JS_PATH ?>/jquery/jquery.fancybox-1.3.2/fancybox/jquery.fancybox-1.3.2.css" type="text/css" media="screen" />
<script type="text/javascript" language="javascript" >
    $(document).ready(function() {
    
        $('#SignatureConfirmation').click(function() {
            var checked = $(this).attr('checked');
            
            if (checked == true) {
                location.href="<?php echo BASE_URL?>/index/shop/checksignature?v=1";
            } else {
                location.href="<?php echo BASE_URL?>/index/shop/checksignature?v=0";
            }
        });
        $("#giftcardpopup").fancybox({
            'transitionIn'	:	'elastic',
            'transitionOut'	:	'elastic',
            'speedIn'		:	600, 
            'speedOut'		:	200, 
            'width'		:	340, 
            'autoScale'		:	true, 
            'overlayShow'	:	true
        });
    });
  $("#giftcardprocesspayment").submit(function(event) {

    // stop form from submitting normally
    event.preventDefault(); 
        
    // get some values from elements on the page:
    var $form = $( this ),
        url = $form.attr( 'action' );

    // Send the data using post and put the results in a div
        $.ajax({
            url: url,
            type: "POST",
            data:{gcno: $('#gcno').val()},
            dataType: "json",
            beforeSend: function(){
                $.prompt('Please wait ...',{ buttons: {} });
            },
            success: function(responseText){
                jQuery.prompt.close();
                $.prompt(responseText.msg,{ buttons: { Ok: true }, zIndex : 1000000000 });
                
                if(responseText.success == true) {
                    /*
                    var value = responseText.giftcardupdate;
                    var oldTotal = $('#totalnotcoupon').val();
                    //if (responseText.success == true) {
                        $("#PromotionCodeMessage").html(''); // empty coupon because you use gift card.
                        
                        $('#estimatetotal').text(oldTotal - value);
                        //var html = $("#PromotionCodeMessage").html();
                        //$("#updategiftcard").html(html + '<br>Saving: $' + value);
                        $("#updategiftcard").html('Gift card: $' + responseText.giftcardupdate);
                        
                    //} else {
                    //    $('#estimatetotal').text(oldTotal);
                    //}
                    */
                    location.href = '<?php echo BASE_URL?>/index/shop/viewcart';
                } else {
                    //$('#estimatetotal').text(oldTotal);
                }
            },
            error: function(html){
                jQuery.prompt.close();
                $.prompt('Please check your gift card...',{ buttons: {} });
            }
        }); 
  });
</script>
